/* 我的订单列表 */
function orderList() {
    new Vue({
        el:'#order_list',
        data() {
            return {
                orderData: [],
                orderList_tabs: ['全部订单', '待付款', '待收货', '待评价'],
                nowIndex: 0,
                orderStatus : null,//订单状态
                current: 1,//第几页
                countSize : 0,//总页数
                keyword : '',//搜索条件
            }
        },
        methods: {
            getData(){
                this.getOrder();
            },
            toggleTabs: function (index) {
                var that = this;
                that.current = 1;
                that.nowIndex = index;
                switch (index){
                    case 0 :
                        that.orderStatus = null
                        break;
                    case 1 :
                        that.orderStatus = 1;
                        break;
                    case 2 :
                        that.orderStatus = 4;
                        break;
                    case 3 :
                        that.orderStatus = 6;
                        break;
                }
                that.getOrder();
            },
            listen: function (index) {
                this.current = index;
                this.getOrder();
            },
            //搜索
            search(){
                this.current = 1;
                this.getOrder();
            },
            //查看订单详情
            getOrderInfo(orderId){
                window.location.href = "../../html/usercenter/order.html?orderId="+orderId;
            },
            //拉取订单列表
            getOrder(){
                var that = this;
                userLogin.ifLogin();
                axios({
                    url : urlParam.domain() + "/api/order/queryDataPC",
                    method : "get",
                    params :{
                        token : urlParam.token(),
                        current : that.current,
                        orderStatus : that.orderStatus,
                        keyword : that.keyword
                    }
                }).then(result=>{
                    that.orderData = result.data.data.rows;
                    that.countSize = result.data.data.total;
                });
            },
            //取消订单
            clearOrder(orderNumber){
                var that= this;
                that.$confirm('此操作将取消订单, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios({
                        url : urlParam.domain() + '/api/order/cancelOrder',
                        method : 'get',
                        params : {
                            token : urlParam.token(),
                            orderNumber : orderNumber
                        }
                    }).then(result=>{
                        that.current = 1;
                        that.getOrder();
                        that.$message({
                            type: 'success',
                            message: '操作成功!'
                        });
                    })

                }).catch(() => {
                    that.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            //立即购买
            buyOrder(orderPayNumber){
                window.location.href = "../../html/usercenter/shopCart.html?orderPayNumber="+orderPayNumber;
            },
            //确认收货
            okOrder(orderNumber){
                var that = this;
                axios({
                    url : urlParam.domain() + "/api/order/confirmReceipt",
                    method : 'get',
                    params : {
                        token : urlParam.token(),
                        orderNumber : orderNumber,
                    }
                }).then(result=>{
                    that.current = 1;
                    that.getOrder();
                    that.$message({
                        type: 'success',
                        message: '操作成功!'
                    });
                })
            },
            //评价商品
            appraiseOrder(orderId){
                window.location.href = '../../html/usercenter/evaluate.html?orderId='+orderId
            },

        },
        created(){
            this.getData();
        }
    })
}


/* 我的订单 */
function order() {
    new Vue({
        el:'#order',
        data() {
            return {
                crumblist:[
                    { text: '我的聚衣'},
                    { text: '我的订单'},
                ],
                orderId : urlParam.href().orderId,//订单id
                orderInfo : {},//订单信息
                status: 0, //订单状态 测试
                statusText : '',//状态文字
                deliveryInfo : {},//物流
            }
        },
        methods : {
            getData(){
                var that = this;
                axios({
                    url : urlParam.domain() + "/api/order/detail",
                    method : "get",
                    params: {
                        token : urlParam.token(),
                        orderId : that.orderId,
                    }
                }).then(result=>{
                    that.orderInfo = result.data.data;
                    that.crumblist.push({text : "订单编号："+result.data.data.orderNumber})
                    switch (result.data.data.orderStatus){
                        case 6 :
                            that.status = 5;
                            that.statusText = '完成';
                            break;
                        case 11 :
                            that.status = 11;
                            that.statusText = '取消订单';
                            break;
                        case 12 :
                            that.status = 12;
                            that.statusText = '自动关闭';
                            break;
                        default:
                            that.status = result.data.data.orderStatus;
                            if (that.status == 1){
                                that.statusText = '待付款';
                            } else if (that.status == 2) {
                                that.statusText = '付款成功';
                            } else if (that.status == 4) {
                                that.statusText = '等待收货';
                            }
                            break;
                    }
                });

                axios({
                    url : urlParam.domain() + "/api/order/queryLogistic",
                    method : "get",
                    params: {
                        token : urlParam.token(),
                        orderId : that.orderId,
                    }
                }).then(result=>{
                    that.deliveryInfo = result.data.data;
                    if (result.data.data){
                        that.deliveryInfo.traces.reverse();
                    }
                });

            },
        },
        created(){
            this.getData();
        },
    })
}